package 剑指offer_leetcode;

/**
 * JZ16数值的整数次方
 */
public class 剑指Offer16_数值的整数次方 {
    //同时不需要考虑大数问题。
    public double myPow(double x, int n) {
        long N = n;
        if(N<0){
            N = -N;
            x = 1/x;
        }
        return Pow(x,N);
    }

    double Pow(double x, long n){
        double res = 1;
        while(n!=0){
            if(n%2==1)
                res *= x;
            x *= x;
            n /= 2;
        }
        return res;
    }
}
